#include "cameraconfig.h"
#include "ui_cameraconfig.h"
#include "../component/componentmanager.h"

CameraConfig::CameraConfig(QWidget* parent)
	: QWidget(parent)
	, ui(new Ui::CameraConfig())
{
	ui->setupUi(this);
	auto algm = component->GetComponent(Component::component_algorithm);
	if (algm) {
		QByteArray input, output;
		if (algm->ExcuteCmd(2, input, output)) {
			QString name = output;
			QStringList names = name.split('-');
			ui->comboBox_2->clear();
			ui->comboBox_2->addItems(names);
		}
	}
}

CameraConfig::~CameraConfig()
{
	delete ui;
}

void CameraConfig::SetCfg(const CameraCfg& cfg)
{
	ui->comboBox->setCurrentText(cfg.type());
	ui->lineEdit->setText(cfg.id());
	ui->lineEdit_2->setText(cfg.ip());
	ui->lineEdit_3->setText(cfg.bd());
	ui->comboBox_2->setCurrentText(cfg.alg());
}
CameraCfg CameraConfig::GetCfg()
{
	CameraCfg cfg = {};
	cfg.type = ui->comboBox->currentText();
	cfg.id() = ui->lineEdit->text();
	cfg.ip() = ui->lineEdit_2->text();
	cfg.bd = ui->lineEdit_3->text();
	cfg.alg = ui->comboBox_2->currentText();
	return cfg;
}
